/**
 * Created by Tsuna Cheung on 2016/12/7.
 */
import React, {Component} from 'react';
import {
    BackAndroid,
    StyleSheet,
    Text,
    View,
    Navigator,
    Platform,
    Image
} from 'react-native';

import Header from '../component/Header'
import AButton from '../component/aButton'
import Login from '../javascriptPage/Login'

export default class RegisterSuccess extends Component {
    constructor(props) {
        super(props);
        this.state = {};
    }

    _backtoRegister = () => {
        const {navigator} = this.props;
        if (navigator) {
            navigator.pop();
        }
    };

    _gotoLogin = () => {
        const {navigator}=this.props;
        if (navigator) {
            navigator.push({
                name: 'Login',
                component: Login
            })
        }
    };

    componentWillMount() {
        if (Platform.OS === 'android') {
            BackAndroid.addEventListener('hardwareBackPress', this.onBackAndroid);
        }
    }

    componentWillUnmount() {
        if (Platform.OS === 'android') {
            BackAndroid.removeEventListener('hardwareBackPress', this.onBackAndroid);
        }
    }

    onBackAndroid = () => {
        const {navigator} = this.props;
        const routers = navigator.getCurrentRoutes();
        if (routers.length > 1) {
            navigator.pop();
            return true;
        }
        return false;
    };

    render() {
        return (
            <View style={styles.container}>
                <Header name="注册成功"
                        function={this._backtoRegister}/>

                <View style={styles.body}>
                    <View style={styles.ImageView}>
                        <Image style={styles.logo}
                               source={require('../Images/职信登入界面.png')}/>
                    </View>

                    <View style={styles.info}>
                        <Text style={styles.info_text}>
                            姓 名：{this.props.name}
                        </Text>

                        <Text style={styles.info_text}>
                            职信号：{this.props.number}
                        </Text>

                        <Text style={styles.info_text}>
                            请登入后补全信息
                        </Text>
                    </View>

                    <View style={styles.buttonView}>
                        <AButton aButtonText="返回"
                                 aButtonFunction={this._gotoLogin}/>
                    </View>
                </View>
            </View>
        );
    }
}

const styles = StyleSheet.create({
    container: {
        flex: 1,
        justifyContent: "center",
        backgroundColor: "#FFFFFF"
    },
    body: {
        flex: 10
    },
    ImageView: {
        alignItems: 'center',
        marginTop: 20
    },
    logo: {
        height: 200,
        width: 200
    },
    info: {
        marginTop: 20,
        alignItems: 'center'
    },
    info_text: {
        fontSize: 20,
        marginTop: 10
    },
    buttonView: {
        alignItems: 'center'
    }

});